package lock;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author tongchen
 * @create 2023-08-11 20:47
 */
public class CASTest {
    public static void main(String[] args) throws InterruptedException {
        //实现原子类
        AtomicInteger atomicInteger = new AtomicInteger();
        //创建两个线程进行不断相加操作
         Thread t1 =new Thread(()->{
             for(int i=0;i<50000;++i){
                 atomicInteger.getAndIncrement();
             }

                 });
         Thread t2 =new Thread(()->{
             for(int i=0;i<50000;++i){
                 atomicInteger.getAndIncrement();
             }
                 });
         t1.start();
         t2.start();
         t1.join();
         t2.join();
        System.out.println(atomicInteger);
    }
}
